package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.iview.IAddProductWorkPartView;
import com.cloudsigns.factorymanager2.produce.model.AddProductWorkPartModel;
import com.cloudsigns.factorymanager2.produce.model.IAddProductWorkPartModel;

public class AddProductWorkPartPresenter {
    private IAddProductWorkPartView view;
    private IAddProductWorkPartModel model;
    private Handler handler = new Handler();

    public AddProductWorkPartPresenter(IAddProductWorkPartView iView) {
        this.view = iView;
        this.model = new AddProductWorkPartModel();
    }

    public void addProductWorkPart() {
        model.addProductWorkPart(view.getName(), new AddProductWorkPartModel.OnAddProductWorkPartListener() {
            @Override
            public void successed() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addProductWorkPartSuccessed();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addProductWorkPartFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
